package org.mcb.zebra.portal.page;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.pluto.PortletWindow;
import org.apache.pluto.PortletWindowID;
import org.mcb.zebra.portal.window.ZebPortletWindow;
import org.mcb.zebra.portal.window.ZebPortletWindowID;
@SuppressWarnings("unchecked")
public class ZebPage implements Page {
	String pageName;
	String url;
	Map<String, PortletWindow> windows = new ConcurrentHashMap<String, PortletWindow>();
	
	/* (non-Javadoc)
	 * @see org.mcb.zebra.portal.page.page#addPortletWindow(java.lang.String, org.apache.pluto.PortletWindow)
	 */
	public PortletWindow addPortletWindow(String id,PortletWindow portletWindow){
		return windows.put(id, portletWindow);
	}
	/* (non-Javadoc)
	 * @see org.mcb.zebra.portal.page.page#containsPortletWindow(java.lang.String)
	 */
	public boolean containsPortletWindow(String id){
		return windows.containsKey(id);
	}
	/* (non-Javadoc)
	 * @see org.mcb.zebra.portal.page.page#remove(java.lang.String)
	 */
	public PortletWindow remove(String id){
		return windows.remove(id);
	}
	
	/* (non-Javadoc)
	 * @see org.mcb.zebra.portal.page.page#getAllPortletWindowt()
	 */
	public Collection getAllPortletWindow(){
		return windows.values();
	}
	/* (non-Javadoc)
	 * @see org.mcb.zebra.portal.page.page#removeAllPortletWindow()
	 */
	public void removeAllPortletWindow(){
		windows.clear();
	}
	/* (non-Javadoc)
	 * @see org.mcb.zebra.portal.page.page#getPortletWindow(java.lang.String)
	 */
	public PortletWindow getPortletWindow(String id){
		return windows.get(id);
	}
	/* (non-Javadoc)
	 * @see org.mcb.zebra.portal.page.page#getPageName()
	 */
	public String getPageName() {
		return pageName;
	}
	/* (non-Javadoc)
	 * @see org.mcb.zebra.portal.page.page#setPageName(java.lang.String)
	 */
	public void setPageName(String pageName) {
		this.pageName = pageName;
	}
	/* (non-Javadoc)
	 * @see org.mcb.zebra.portal.page.page#addPortletWindow(java.lang.String, java.lang.String)
	 */
	public void addPortletWindow(String portletContext,String portletName){
		PortletWindowID  windowID = ZebPortletWindowID.getId(portletContext, portletName);
		String id = windowID.getStringId();
		addPortletWindow(id, ZebPortletWindow.getPortletWindow(portletContext, portletName,windowID));
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
}
